package crm8000.services

import groovy.sql.Sql
import javax.sql.DataSource

class PermissionService {
	def DataSource dataSource

	def UserService userService

	def hasPermission(String fid) {
		def sql = new Sql(dataSource)
		def cnt = sql.firstRow(''' select count(p.fid) as fidCounts
                        from t_user_role ur, t_role_permission rp, t_permission p
                        where ur.user_id = ? and ur.role_id = rp.role_id 
                            and rp.permission_id = p.permission_id
                            and p.fid = ? ''', [userService.loginUserId, fid]);


		return cnt.fidCounts > 0
	}
}